'''
Created on Oct 17, 2012

@author: raygomez
'''
import sys
import binascii
from Message import Message
import xdrlib
import re

if __name__ == '__main__':
    filename = sys.argv[1]
    file = open(filename, "rt")
    text = file.read().strip()
    e = re.compile(r"\s+")
    text = e.sub("", text)
    
    raw = binascii.a2b_hex(text)

    unpacker = xdrlib.Unpacker(raw)
    msg = Message()
    result = msg.decode(unpacker, len(raw))
    
    if result == Message.DECODE_STATUS_DECODED:
        print(msg)
    else:
        print("Sorry ,cannot be decoded")
    
    